import 'package:finance_app/src/entities/payslips_entity.dart';

payslipsEntityFromJson(PayslipsEntity data, Map<String, dynamic> json) {
	if (json['interval'] != null) {
		data.interval = json['interval'] is String
				? num.tryParse(json['interval'])
				: json['interval'];
	}
	if (json['chartData'] != null) {
		data.chartData = (json['chartData'] as List).map((v) => PayslipsChartDataEntity().fromJson(v)).toList();
	}
	return data;
}

Map<String, dynamic> payslipsEntityToJson(PayslipsEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['interval'] = entity.interval;
	data['chartData'] =  entity.chartData?.map((v) => v.toJson())?.toList();
	return data;
}

payslipsChartDataEntityFromJson(PayslipsChartDataEntity data, Map<String, dynamic> json) {
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['value'] != null) {
		data.value = json['value'] is String
				? num.tryParse(json['value'])
				: json['value'];
	}
	return data;
}

Map<String, dynamic> payslipsChartDataEntityToJson(PayslipsChartDataEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['name'] = entity.name;
	data['value'] = entity.value;
	return data;
}